package com.wdcg.view.adapter;

import java.util.List;

import com.wdcg.R;
import com.wdcg.model.access.BonusAccess;
import com.wdcg.model.dao.BonusDescription;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * @author Grzegorz Matyszczak<BR>
 *
 */
public class BonusesListAdapter extends BaseAdapter {

	private Context context;
	private List<BonusDescription> bonuses;
	
	public BonusesListAdapter(Context context, List<BonusDescription> bonuses) {
		this.context = context;
		this.bonuses = bonuses;
	}
	
	public int getCount() {
		return bonuses.size();
	}

	public Object getItem(int position) {
		return bonuses.get(position);
	}

	public long getItemId(int position) {
		return 0;
	}

	public View getView(int position, View convertView, ViewGroup parent) {	 
        LayoutInflater inflater = (LayoutInflater)context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
        View view = inflater.inflate(R.layout.item_list_bonuses, null);
        BonusDescription bonus = bonuses.get(position);
        ((ImageView)view.findViewById(R.id.bonusImageView)).setImageResource(context.getResources().getIdentifier("@drawable/"+bonus.getBonus().getImgTitle(), null, context.getPackageName()));
        ((TextView)view.findViewById(R.id.bonusNameTextView)).setText(BonusAccess.getBonusTypeDescriptionForBonusDescription(bonus).getName());
        ((TextView)view.findViewById(R.id.bonusPlaceNameTextView)).setText(bonus.getName());
        return view;
	}


}
